﻿using AiBLSmartEdu.Module.Chemistry.API.Services;
using AiBLSmartEdu.Module.SmartChemistry.API.DTOs;
using AiBLSmartEdu.Module.SmartPhysics.API.DTOs;
using FrameworkCore;
using FrameworkCore.Controllers;
using FrameworkCore.Hubs;
using FrameworkCore.Interfaces;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;

namespace AiBLSmartEdu.Module.Chemistry.API.Controllers;

/// <summary>
/// 化学问题提问助手
/// </summary>
[AllowAnonymous]
public class SmartChemistryController : BaseModuleController
{
    private readonly ChemistryAskServices _chemistryAskServices;
    private readonly IHubContext<SignalRHub> _hubContext;
    private readonly ICurrentUserService _currentUserService;
    private readonly ChemistryAskHelpers _chemistryAskHelpers;

    public SmartChemistryController(
        ChemistryAskServices chemistryAskServices,
        IHubContext<SignalRHub> hubContext,
        ICurrentUserService currentUserService,
        ChemistryAskHelpers chemistryAskHelpers)
    {
        _chemistryAskServices = chemistryAskServices;
        _hubContext = hubContext;
        _currentUserService = currentUserService;
        _chemistryAskHelpers = chemistryAskHelpers;
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="filter">分页输入模型</param>
    /// <returns></returns>
    [HttpGet("Page")]
    public async Task<PageResult<ChemistryAskOutputModel>> PaginationAsync([FromQuery] ChemistryAskPaginationFilter filter)
    {
        return await _chemistryAskServices.PageAsync(filter);
    }

    /// <summary>
    /// 提问问题
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Result> CreateAsync(ChemistryAskCreateInputModel input)
    {
        await _chemistryAskServices.CreateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 清空用户数据
    /// </summary>
    /// <returns></returns>
    [HttpDelete]
    public async Task<Result> ClearAsync()
    {
        await _chemistryAskServices.ClearByUserIdAsync();
        return await Result.SucceedAsync();
    }
}